package o;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.huawei.appgallery.forum.base.card.bean.Section;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.gamebox.service.welfare.gift.bean.GetGiftExchangeResponse;
import com.huawei.gamebox.service.welfare.gift.bean.GiftCardBean;
import com.huawei.gamebox.service.welfare.gift.bean.PlayerRoleInfo;
import com.huawei.gamebox.service.welfare.gift.bean.QueryPlayerRoleResponse;
import com.huawei.hms.support.api.entity.sns.SNSCode.Status;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class fbx {
    private GiftCardBean ˋ;
    private Context ˎ;
    private int ॱ;

    class a implements o.ckh.a {
        final /* synthetic */ fbx ˏ;

        private a(fbx o_fbx) {
            this.ˏ = o_fbx;
        }

        public void ˏ(AlertDialog alertDialog, com.huawei.appgallery.foundation.ui.framework.widget.dialog.dialogactivity.DialogActivity.a aVar, int i) {
            if (alertDialog == null) {
                return;
            }
            if (-2 == i) {
                alertDialog.dismiss();
            } else if (-1 == i) {
                PermissionChecker.ˋ((Activity) this.ˏ.ˎ, 14);
            }
        }
    }

    class b implements o.ckh.a {
        private PlayerRoleInfo ˊ;
        private String ˋ;
        private int ˎ;
        final /* synthetic */ fbx ॱ;

        b(fbx o_fbx, int i, PlayerRoleInfo playerRoleInfo, String str) {
            this.ॱ = o_fbx;
            this.ˎ = i;
            this.ˊ = playerRoleInfo;
            this.ˋ = str;
        }

        public void ˏ(AlertDialog alertDialog, com.huawei.appgallery.foundation.ui.framework.widget.dialog.dialogactivity.DialogActivity.a aVar, int i) {
            if (alertDialog == null) {
                return;
            }
            if (-2 == i) {
                alertDialog.dismiss();
            } else if (-1 == i) {
                bwx o_bwx = (bwx) fho.ˏ().ˋ("Operation").ॱ(bwx.class);
                Section section = new Section();
                section.ॱ(this.ˎ);
                o_bwx.ˏ(this.ॱ.ˎ, section, 0, ((bus) fho.ˏ().ˋ("Forum").ॱ(bus.class)).ˎ()).ˏ(new fjq<Boolean>(this) {
                    final /* synthetic */ b ˏ;

                    {
                        this.ˏ = r1;
                    }

                    public void onComplete(fjo<Boolean> o_fjo_java_lang_Boolean) {
                        if (o_fjo_java_lang_Boolean.ˊ() && ((Boolean) o_fjo_java_lang_Boolean.ॱ()).booleanValue()) {
                            this.ˏ.ॱ.ॱ(this.ˏ.ˊ, this.ˏ.ˋ);
                        }
                    }
                });
            }
        }
    }

    class c implements o.ckh.a {
        final /* synthetic */ fbx ˋ;

        private c(fbx o_fbx) {
            this.ˋ = o_fbx;
        }

        public void ˏ(AlertDialog alertDialog, com.huawei.appgallery.foundation.ui.framework.widget.dialog.dialogactivity.DialogActivity.a aVar, int i) {
            if (alertDialog == null) {
                return;
            }
            if (-2 == i) {
                alertDialog.dismiss();
            } else if (-1 == i) {
                ced.ˎ(this.ˋ.ˎ, this.ˋ.ˋ.ॱـ(), this.ˋ.ˋ.ᐝॱ());
            }
        }
    }

    public fbx(Context context, GiftCardBean giftCardBean, int i) {
        this.ˎ = context;
        this.ˋ = giftCardBean;
        this.ॱ = i;
    }

    public void ˏ() {
        if (this.ˋ.ʻॱ() == 0) {
            ˋ(null);
        } else if (1 == this.ˋ.ʻॱ()) {
            ॱ();
        }
    }

    private void ॱ() {
        fbh.ˋ(fca.ˏ(this.ˋ), new IServerCallBack(this) {
            final /* synthetic */ fbx ˎ;

            {
                this.ˎ = r1;
            }

            public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
            }

            public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                if (!(responseBean instanceof QueryPlayerRoleResponse)) {
                    return;
                }
                if (responseBean.getResponseCode() == 0) {
                    int rtnCode_ = responseBean.getRtnCode_();
                    if (rtnCode_ == 0) {
                        List ˋ = ((QueryPlayerRoleResponse) responseBean).ˋ();
                        if (!this.ˎ.ˎ(ˋ)) {
                            this.ˎ.ˏ(-1000);
                            return;
                        } else if (1 == ˋ.size()) {
                            this.ˎ.ˋ((PlayerRoleInfo) ˋ.get(0));
                            return;
                        } else {
                            this.ˎ.ˊ(ˋ);
                            return;
                        }
                    }
                    this.ˎ.ˏ(rtnCode_);
                    return;
                }
                this.ˎ.ˏ(responseBean);
            }
        });
    }

    private boolean ˎ(List<PlayerRoleInfo> list) {
        if (!CollectCheck.isEmpty(list)) {
            for (PlayerRoleInfo ˏ : list) {
                if (!TextUtils.isEmpty(ˏ.ˏ())) {
                    return true;
                }
            }
        }
        return false;
    }

    public void ˋ(final PlayerRoleInfo playerRoleInfo) {
        if (!ˎ(this.ˋ.ʿ())) {
            Logger.ˎ("GetGiftsExchangeManager", "gift not allow exchange:" + this.ˋ.ʿ());
        } else if (this.ˋ.ʿ() == 1) {
            fco.ˋ(new o.fco.c(this) {
                final /* synthetic */ fbx ˋ;

                public void ˋ(String str) {
                    if (TextUtils.isEmpty(str)) {
                        Logger.e("GetGiftsExchangeManager", "certificateChainStr is null, gift exchange fail!");
                        fcl.ˎ(this.ˋ.ˎ.getString(exp$f.ʾॱ));
                        return;
                    }
                    this.ˋ.ॱ(playerRoleInfo, str);
                }
            });
        } else {
            ॱ(playerRoleInfo, null);
        }
    }

    private void ॱ(final PlayerRoleInfo playerRoleInfo, final String str) {
        fbh.ˋ(fbz.ˏ(this.ˋ, this.ॱ, playerRoleInfo, str), new IServerCallBack(this) {
            final /* synthetic */ fbx ˊ;

            public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
            }

            public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                if (!(responseBean instanceof GetGiftExchangeResponse)) {
                    return;
                }
                if (responseBean.getResponseCode() == 0) {
                    GetGiftExchangeResponse getGiftExchangeResponse = (GetGiftExchangeResponse) responseBean;
                    int rtnCode_ = getGiftExchangeResponse.getRtnCode_();
                    if (rtnCode_ == 0 || rtnCode_ == 103005) {
                        this.ˊ.ˋ.ˎ(2);
                        this.ˊ.ˋ.ॱ(getGiftExchangeResponse.ʼ());
                        CharSequence ʽ = getGiftExchangeResponse.ʽ();
                        if (8 != this.ˊ.ˋ.ॱᐝ()) {
                            if (9 == this.ˊ.ˋ.ॱᐝ()) {
                                this.ˊ.ॱ(playerRoleInfo);
                            } else if (!TextUtils.isEmpty(ʽ)) {
                                this.ˊ.ˏ(rtnCode_, getGiftExchangeResponse);
                            }
                        } else if (rtnCode_ == 103005) {
                            fcl.ˎ(exp$f.ˏˏ);
                        } else {
                            fcl.ˎ(exp$f.ꜟ);
                        }
                        eyh.ˏ();
                        this.ˊ.ˋ();
                        return;
                    } else if (rtnCode_ == 103014) {
                        this.ˊ.ˎ(getGiftExchangeResponse, playerRoleInfo, str);
                        return;
                    } else {
                        this.ˊ.ˏ(rtnCode_);
                        return;
                    }
                }
                this.ˊ.ˏ(responseBean);
            }
        });
    }

    private void ˏ(int i, GetGiftExchangeResponse getGiftExchangeResponse) {
        this.ˋ.ˏ(getGiftExchangeResponse.ʽ());
        if (i == 103005) {
            fcl.ˎ(exp$f.ˏˏ);
            return;
        }
        fcl.ˋ(this.ˋ.ͺ(), this.ˎ);
        fcl.ˎ(exp$f.ꓸ);
    }

    private boolean ˎ(int i) {
        if (i == 1) {
            if (etp.ˋ()) {
                Logger.ˋ("GetGiftsExchangeManager", "device is root, not allow exchange!");
                fcl.ˎ(this.ˎ.getString(exp$f.ʾॱ));
                return false;
            } else if (!ˊ()) {
                if (!(this.ˎ instanceof Activity)) {
                    return false;
                }
                ˎ();
                return false;
            }
        }
        return true;
    }

    private boolean ˊ() {
        if (VERSION.SDK_INT >= 23 && this.ˎ.checkSelfPermission("android.permission.READ_PHONE_STATE") != 0) {
            return false;
        }
        return true;
    }

    private void ˎ(@NonNull GetGiftExchangeResponse getGiftExchangeResponse, PlayerRoleInfo playerRoleInfo, String str) {
        Map ʻ = getGiftExchangeResponse.ʻ();
        if (ʻ == null) {
            Logger.e("GetGiftsExchangeManager", "ExtParams is null");
            return;
        }
        String str2 = (String) ʻ.get("fid");
        if (TextUtils.isEmpty(str2)) {
            Logger.e("GetGiftsExchangeManager", "fid String is empty");
            return;
        }
        try {
            int parseInt = Integer.parseInt(str2);
            fcd o_fcd = new fcd();
            o_fcd.ˋ("GetGiftsExchangeManager");
            o_fcd.ˊ(null);
            o_fcd.ˎ(this.ˎ.getString(exp$f.ʽˊ, new Object[]{this.ˋ.ᐝॱ()}));
            o_fcd.ˏ(this.ˎ.getString(exp$f.ˊˊ));
            o_fcd.ॱ(this.ˎ.getString(exp$f.ॱˎ));
            o_fcd.ˎ(new b(this, parseInt, playerRoleInfo, str));
            fcl.ˊ(this.ˎ, o_fcd, this.ॱ);
        } catch (Exception e) {
            Logger.e("GetGiftsExchangeManager", "fid is not valid:" + str2);
        }
    }

    private void ˏ(ResponseBean responseBean) {
        if (3 == responseBean.getResponseCode()) {
            fcl.ˎ(fcl.ॱ(exp$f.ᐧ));
            return;
        }
        fcl.ˎ(fcl.ॱ(exp$f.ꜞ));
        Logger.e("GetGiftsExchangeManager", "queryRole http " + responseBean.getHttpStatusCode());
    }

    private void ˏ(int i) {
        String ॱ;
        boolean z;
        int i2 = 0;
        int i3 = 1;
        String ॱ2 = fcl.ॱ(exp$f.ᶥ);
        String str = null;
        String ॱ3 = fcl.ॱ(exp$f.ˉ);
        switch (i) {
            case -1000:
                ॱ = fcl.ॱ(exp$f.ᐝᐝ);
                ॱ2 = fcl.ॱ(exp$f.ʼˋ);
                if (fcl.ˊ(this.ॱ)) {
                    i3 = 0;
                } else {
                    str = fcl.ॱ(exp$f.ꞌ);
                    ॱ3 = fcl.ॱ(exp$f.ˉ);
                }
                Logger.e("GetGiftsExchangeManager", "GIFT_NEED_CREATE_ROLE");
                int i4 = i3;
                z = false;
                i2 = i4;
                break;
            case 10035:
                ॱ = fcl.ॱ(exp$f.ˎˎ);
                this.ˋ.ˎ(4);
                Logger.e("GetGiftsExchangeManager", "forum_ranking_not_enought");
                break;
            case 10037:
                ॱ = fcl.ॱ(exp$f.ᐨ);
                z = false;
                break;
            case 103001:
                Logger.e("GetGiftsExchangeManager", "GIFT_REATCH_MAX_LIMIT");
                ॱ = fcl.ॱ(exp$f.ﹳ);
                z = false;
                break;
            case 103003:
                ॱ = fcl.ॱ(exp$f.ͺॱ);
                this.ˋ.ˎ(3);
                this.ˋ.ॱ(0);
                Logger.e("GetGiftsExchangeManager", "award_exchanged_over");
                break;
            case 103008:
                ॱ = fcl.ॱ(exp$f.ʻᐝ);
                this.ˋ.ˎ(1);
                Logger.e("GetGiftsExchangeManager", "user_level_not_enought");
                break;
            default:
                ॱ = ॱ(i);
                z = false;
                break;
        }
        ˋ(z);
        if (i2 != 0) {
            ˋ(ॱ2, ॱ, str, ॱ3);
        } else {
            fcl.ˎ(ॱ);
        }
    }

    private void ˋ(boolean z) {
        if (z) {
            eyh.ˏ();
        }
    }

    private String ॱ(int i) {
        String ॱ = fcl.ॱ(exp$f.ꜞ);
        switch (i) {
            case 3002:
                ॱ = fcl.ॱ(exp$f.ॱͺ);
                Logger.e("GetGiftsExchangeManager", "NETWORK_IS_BUSY");
                return ॱ;
            case 3004:
                return fcl.ॱ(exp$f.ॱʼ);
            case Status.GET_USER_DATA_FAIL /*3005*/:
                return fcl.ॱ(exp$f.ʾॱ);
            case 10030:
                Logger.e("GetGiftsExchangeManager", "GIFT_HAS_CLAIMED_BY_DEVICE");
                return fcl.ॱ(exp$f.ˎˏ);
            case 103009:
                ॱ = fcl.ॱ(exp$f.ʻॱ);
                Logger.e("GetGiftsExchangeManager", "black_user");
                return ॱ;
            case 103010:
                ॱ = fcl.ॱ(exp$f.ﾞ);
                Logger.e("GetGiftsExchangeManager", "ONLY_NEW_VERSION_SUPPORT");
                return ॱ;
            case 103011:
                ॱ = fcl.ॱ(exp$f.ʼॱ);
                Logger.e("GetGiftsExchangeManager", "CURRENT_ZONE_NOT_SUPPORT");
                return ॱ;
            case 103012:
                ॱ = fcl.ॱ(exp$f.ʻˋ, this.ˋ.ᐝॱ());
                Logger.e("GetGiftsExchangeManager", "GIFT_CP_SERVER_BUSY");
                return ॱ;
            case 103013:
                return fcl.ॱ(exp$f.ᐝˊ, this.ˋ.ᐝॱ());
            default:
                return ॱ;
        }
    }

    private void ˋ() {
        Intent intent = new Intent();
        intent.setAction("com.huawei.gamebox.refreshBuoyGiftCard");
        intent.putExtra("refresh.observer.id", this.ˋ.ᐝ());
        intent.putExtra("refresh.observer.value", this.ˋ.ͺ());
        ll.ˏ(this.ˎ).ˋ(intent);
    }

    private void ˋ(String str, String str2, String str3, String str4) {
        fcd o_fcd = new fcd();
        o_fcd.ˋ("GetGiftsExchangeManager");
        o_fcd.ˊ(str);
        o_fcd.ˎ(str2);
        o_fcd.ˏ(str3);
        o_fcd.ॱ(str4);
        o_fcd.ˎ(new c());
        fcl.ˊ(this.ˎ, o_fcd, this.ॱ);
    }

    private void ˊ(List<PlayerRoleInfo> list) {
        List arrayList = new ArrayList();
        for (PlayerRoleInfo playerRoleInfo : list) {
            if (!(playerRoleInfo == null || TextUtils.isEmpty(playerRoleInfo.ˏ()) || TextUtils.isEmpty(playerRoleInfo.ॱ()))) {
                arrayList.add(playerRoleInfo);
            }
        }
        fcl.ˏ(this.ˎ, arrayList, this.ˋ, this.ॱ);
    }

    private void ॱ(PlayerRoleInfo playerRoleInfo) {
        String string = this.ˎ.getString(exp$f.ㆍ, new Object[]{this.ˋ.ᐝॱ()});
        if (fcl.ˊ(this.ॱ) && playerRoleInfo == null) {
            fcl.ˎ(string);
            return;
        }
        fcd o_fck = new fck();
        o_fck.ˋ("GetGiftsExchangeManager");
        o_fck.ˊ(fcl.ॱ(exp$f.ꜟ));
        o_fck.ˏ(fcl.ॱ(exp$f.ʹ));
        o_fck.ॱ(fcl.ॱ(exp$f.ˉ));
        if (fcl.ˊ(this.ॱ)) {
            o_fck.ˏ(null);
            o_fck.ॱ(fcl.ॱ(exp$f.ˉ));
        }
        o_fck.ˏ(playerRoleInfo);
        o_fck.ॱॱ(string);
        o_fck.ˎ(this.ˎ);
        o_fck.ˎ(new c());
        fcl.ˊ(this.ˎ, o_fck, this.ॱ);
    }

    private void ˎ() {
        fcd o_fcd = new fcd();
        o_fcd.ˋ("GetGiftsExchangeManager");
        o_fcd.ˊ(null);
        o_fcd.ˎ(this.ˎ.getString(exp$f.ʽᐝ));
        o_fcd.ˏ(this.ˎ.getString(exp$f.ˏ));
        o_fcd.ॱ(this.ˎ.getString(exp$f.ॱˎ));
        o_fcd.ˎ(new a());
        fcl.ˊ(this.ˎ, o_fcd, this.ॱ);
    }
}
